package edu.tapestry.iddb.client.webService;

import iddb.AddBuddyCommand;
import iddb.AddGroupCommand;
import iddb.AddIMUserCommand;
import iddb.ChangeIMUserCommand;
import iddb.ConnectCommand;
import iddb.ConnectionPresence;
import iddb.GetBuddiesCommand;
import iddb.GetGroupCommand;
import iddb.GetGroupsCommand;
import iddb.GetMessagesCommand;
import iddb.GetProfileCommand;
import iddb.GetProfilesCommand;
import iddb.LoginCommand;
import iddb.LogoutCommand;
import iddb.NewProfilCommand;
import iddb.PluginIdentificator;
import iddb.RegisterCommand;
import iddb.RejectCommand;
import iddb.RemoveBuddyCommand;
import iddb.RemoveGroupCommand;
import iddb.RemoveIMUserCommand;
import iddb.RenameProfilCommand;
import iddb.SendMessageCommand;
import iddb.SimpleConnectCommand;
import iddb.SwitchProfilCommand;


public class CommandsGenerator {

	public static LoginCommand createLogin(String username, String passwd, String profil, boolean isVisible){
		LoginCommand cmd = new LoginCommand();
		cmd.setUsername(username);
		cmd.setPasswd(passwd);
		cmd.setProfil(profil);
		cmd.setIsVisible(isVisible);
		
		return cmd;
	}
	
	
	public static RegisterCommand createRegister(String username, String passwd, String email){
		RegisterCommand cmd = new RegisterCommand();
		cmd.setUsername(username);
		cmd.setPasswd(passwd);
		cmd.setEmail(email);
		
		return cmd;
	}
	
	public static LogoutCommand createLogout(){
		return new LogoutCommand();
	}
	
	public static NewProfilCommand createNewProfil(String name){
		NewProfilCommand cmd = new NewProfilCommand();
		cmd.setProfilname(name);
		
		return cmd;
	}
	
	public static RenameProfilCommand createRenameProfil(String oldName, String newName){
		RenameProfilCommand cmd = new RenameProfilCommand();
		cmd.setNewProfilname(newName);
		cmd.setOldProfilname(oldName);
		
		return cmd;
	}
	
	public static SwitchProfilCommand createSwitchProfil(String name, int type){
		SwitchProfilCommand cmd = new SwitchProfilCommand();
		cmd.setProfilname(name);
		cmd.setType(type);
		
		return cmd;
	}
	
	public static AddIMUserCommand createAddIMUser(String username, String passwd, String type, String srvAddr, int srvPort, String profile, String presence, int operation){
		AddIMUserCommand cmd = new AddIMUserCommand();
		cmd.setImUsername(username);
		cmd.setImPasswd(passwd);
		cmd.setImType(type);
		cmd.setProfilname(profile);
		cmd.setServerName(srvAddr);
		cmd.setServerPort(srvPort);
		ConnectionPresence p = null;
		if (presence.charAt(0) == 'd'){
			p = ConnectionPresence.DISCONNECT;
		}
		
		if (presence.charAt(0) == 'v'){
			p = ConnectionPresence.VISIBLE;
		}
		
		if (presence.charAt(0) == 'i'){
			p = ConnectionPresence.INVISIBLE;
		}
		cmd.setPresence(p);
		cmd.setOperation(operation);
		
		return cmd;
	}
	
	public static AddBuddyCommand createAddBuddy(String username, String nick, String group, PluginIdentificator ident){
		AddBuddyCommand cmd = new AddBuddyCommand();
		cmd.setUsername(username);
		cmd.setNick(nick);
		cmd.setGroupname(group);
		cmd.setPluginIdentificator(ident);
		
		return cmd;
	}
	
	public static RemoveBuddyCommand createRemoveBuddy(PluginIdentificator ident, String username, String group){
		RemoveBuddyCommand cmd = new RemoveBuddyCommand();
		cmd.setUsername(username);
		cmd.setGroupname(group);
		cmd.setPluginIdentificator(ident);
		
		return cmd;
	}
	
	public static AddGroupCommand createAddGroup(String name, PluginIdentificator ident){
		AddGroupCommand cmd = new AddGroupCommand();
		cmd.setGroupname(name);
		cmd.setPluginIdentificator(ident);
		
		return cmd;
	}
	
	public static RemoveGroupCommand createRemoveGroup(String name, PluginIdentificator ident){
		RemoveGroupCommand cmd = new RemoveGroupCommand();
		cmd.setGroupname(name);
		cmd.setPluginIdentificator(ident);
		
		return cmd;
	}
	
	// TODO udelat odpovidaji stranku RejectBuddyIM.java
	public static RejectCommand createReject(String name, PluginIdentificator ident){
		RejectCommand cmd = new RejectCommand();
		cmd.setPluginIdentificator(ident);
		cmd.setUsername(name);
	
		return cmd;
	}
	
	public static GetProfilesCommand getProfiles(){
		return new GetProfilesCommand();
	}
	
	public static ConnectCommand createConnectCommand(){
		return new ConnectCommand();
	}
	
	public static RemoveIMUserCommand createRemoveIMUserCommand(Long id){
		RemoveIMUserCommand cmd = new RemoveIMUserCommand();
		cmd.setIdent(id);
		
		return cmd; 
	}
	
	public static GetProfileCommand createGetProfile(String name){
		GetProfileCommand cmd = new GetProfileCommand();
		cmd.setProfilname(name);
		
		return cmd;
	}
	
	public static ChangeIMUserCommand changeIMUserCmd(String username, String passwd, String type, String srvAddr, int srvPort, String profile, String presence, int operation){
		ChangeIMUserCommand cmd = new ChangeIMUserCommand();
		cmd.setImUsername(username);
		cmd.setImPasswd(passwd);
		cmd.setImType(type);
		cmd.setServerName(srvAddr);
				
		return cmd;
	}
	
	public static GetGroupsCommand getGroupsCmd(PluginIdentificator ident){
		GetGroupsCommand cmd = new GetGroupsCommand();
		cmd.setPluginIdentificator(ident);
		
		return cmd;
	}
	
	public static GetGroupCommand getGroupCmd(PluginIdentificator ident, String groupname){
		GetGroupCommand cmd = new GetGroupCommand();
		cmd.setPluginIdentificator(ident);
		cmd.setGroupname(groupname);
		
		return cmd;
	}
	
	public static SimpleConnectCommand simpleConnCmd(String username, String type, String srvAddr){
		SimpleConnectCommand cmd = new SimpleConnectCommand();
		cmd.setUsername(username);
		cmd.setType(type);
		cmd.setServer(srvAddr);
		
		return cmd;
	}
	
	// TODO odstranit 'String group'
	public static GetBuddiesCommand getBuddiesCmd(String group, PluginIdentificator ident){
		GetBuddiesCommand cmd = new GetBuddiesCommand();
		//cmd.setGroupname(group);
		cmd.setPluginIdentificator(ident);
		return  cmd;
	}
	
	public static SendMessageCommand sendMessageCmd(PluginIdentificator ident, String toUsername, String message){
		SendMessageCommand cmd = new SendMessageCommand();
		cmd.setPluginIdentificator(ident);
		cmd.setTo(toUsername);
		cmd.setMessage(message);
		return cmd;
	}
	
	public static GetMessagesCommand getMessagesCmd(PluginIdentificator ident){
		GetMessagesCommand cmd = new GetMessagesCommand();
		cmd.setPluginIdentificator(ident);
		return cmd;
	}
	
	
	
	
	
	
	
	
	
}
